package com.itheima.ThreadTest.synchronize;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Account {
    private String card;
    private int money;
    private final Lock lk = new ReentrantLock();

    // synchronized
    public void drawMoney(int money) {
        String name = Thread.currentThread().getName();
//        synchronized ("a") {
        lk.lock();
        if (this.money >= money) {
            System.out.println(name + "来取" + money + "成功");
            this.money -= money;
            System.out.println(name + "取走" + money + "剩余" + this.money);
        } else {
            System.out.println(name + "余额不足~");
        }
        lk.unlock();
//        }
    }

    public Account() {
    }

    public Account(String card, int money) {
        this.card = card;
        this.money = money;
    }

    public String getCard() {
        return card;
    }

    public void setCard(String card) {
        this.card = card;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }
}
